luffy.common.TemplateRepos = new function(){
	this.get = function(id) {
		if (typeof id == "string") {
			if (!this._template[id]) {
				throw new Error("Requested template id(" + id + ") is not found.");
			}
			return luffy.common.Template.get(this._template[id]); 
		}
		
		if (typeof id == "object") {
			if (!this._template[id.id]) {
				throw new Error("Requested template id(" + id.id + ") is not found.");
			}
			
			var fMainTemplate = this._template[id.id];
			var htSubTemplates = {};
			
			for (var sPlaceholderId in id.subTemplates)  {
				var sSubTemplateId = id.subTemplates[sPlaceholderId].id;
				
				if (!this._template[id.id]) {
					throw new Error("Requested template id(" + sSubTemplateId + " in " + id.id + ") is not found.");
				}
				
				htSubTemplates[sPlaceholderId] = this._template[sSubTemplateId];
			}
			
			return luffy.common.Template.get(function (oData) {
				var htPartialHTML = {};
				
				for (var sPlaceholderId in htSubTemplates) {
					var fSubTemplate = htSubTemplates[sPlaceholderId];
					htPartialHTML[sPlaceholderId] = fSubTemplate(oData);
				}
				
				return fMainTemplate(htPartialHTML);
			});
		}
	}

	this._template = {%=REPLACEMENT%}
};